home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / TODO.PAK / TODODLGS.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  7KB  |  263 lines

  1. //---------------------------------------------------------------------
  2. //
  3. //  TODODLGS.CPP - part of TODO example program
  4. //
  5. //      Copyright (c) 1991, 1993 by Borland International
  6. //      All Rights Reserved.
  7. //
  8. //---------------------------------------------------------------------
  9.  
  10.  
  11. #include <services/wsysinc.h>
  12. #include <windowsx.h>
  13. #include <string.h>
  14.  
  15. #include "tododlgs.h"
  16. #include "tododefs.h"
  17.  
  18. //---------------------------------------------------------------------
  19. //
  20. //  member functions for class AboutBox.
  21. //
  22. //  not much needed here...
  23. //
  24. //---------------------------------------------------------------------
  25.  
  26. LPSTR AboutBox::GetDialogName()
  27. {
  28.     return "AboutBox";
  29. }
  30.  
  31. BOOL AboutBox::Dispatch( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
  32. {
  33.     switch( msg )
  34.         {
  35.  
  36.         case WM_INITDIALOG:
  37.  
  38.             return TRUE;                // no initialization.
  39.  
  40.         case WM_COMMAND:
  41.  
  42.             if( GET_WM_COMMAND_ID(wParam, lParam) == IDOK ||
  43.             GET_WM_COMMAND_ID(wParam, lParam) == IDCANCEL )
  44.             {
  45.             EndDialog( hDlg, TRUE );    // selecting OK or Cancel
  46.             return TRUE;                // terminates the dialog
  47.             }
  48.  
  49.         default:                        // if we don't handle it, pass it
  50.                                         // to our parent.
  51.  
  52.             return ModalDialog::Dispatch( hDlg, msg, wParam, lParam );
  53.  
  54.   }
  55. }
  56.  
  57. //---------------------------------------------------------------------
  58. //
  59. //  member functions for class FileBox.
  60. //
  61. //---------------------------------------------------------------------
  62.  
  63. BOOL FileBox::GetOpenFileName( HWND handle, char *fileName, char *titleName )
  64. {
  65.     ofn.hwndOwner = handle;
  66.     ofn.lpstrFile = fileName;
  67.     ofn.lpstrFileTitle = titleName;
  68.     ofn.Flags = OFN_FILEMUSTEXIST;
  69.     return ::GetOpenFileName( &ofn );
  70. }
  71.  
  72. BOOL FileBox::GetSaveFileName( HWND handle, char *fileName, char *titleName )
  73. {
  74.     ofn.hwndOwner = handle;
  75.     ofn.lpstrFile = fileName;
  76.     ofn.lpstrFileTitle = titleName;
  77.     ofn.Flags = OFN_OVERWRITEPROMPT;
  78.  
  79.     return ::GetOpenFileName( &ofn );
  80. }
  81.  
  82. OPENFILENAME FileBox::ofn =
  83. {
  84.     sizeof(OPENFILENAME),       // lStructSize
  85.     0,                          // hwndOwner
  86.     0,                          // hInstance
  87.     filters[0],                 // lpstrFilter
  88.     0,                          // lpstrCustomFilter
  89.     0,                          // nMaxCustFilter
  90.     0,                          // nFilterIndex
  91.     0,                          // lpstrFile
  92.     MAXPATH,                    // nMaxFile
  93.     0,                          // lpstrFileTitle
  94.     MAXFILE+MAXEXT,             // nMaxFileTitle
  95.     0,                          // lpstrInitialDir
  96.     0,                          // lpstrTitle
  97.     0,                          // Flags
  98.     0,                          // nFileOffset
  99.     0,                          // nFileExtension
  100.     "tdo",                      // lpstrDefExt
  101.     0,                          // lCustData
  102.     0,                          // lpfnHook
  103.     0                           // lpTemplateName
  104. };
  105.  
  106. char *FileBox::filters[] =
  107. {
  108.     "Todo Files (*.TDO)",   "*.tdo",
  109.     "All Files (*.*)",      "*.*",
  110.     ""
  111. };
  112.  
  113.  
  114. //---------------------------------------------------------------------
  115. //
  116. //  member functions for class EditBox.
  117. //
  118. //---------------------------------------------------------------------
  119.  
  120. LPSTR EditBox::GetDialogName()
  121. {
  122.     return "TodoEdit";
  123. }
  124.  
  125. //---------------------------------------------------------------------
  126. //
  127. //  void EditBox::InitDlg( HWND hDlg );
  128. //
  129. //  initializes the dialog box.
  130. //
  131. //---------------------------------------------------------------------
  132.  
  133. void EditBox::InitDlg( HWND hDlg )
  134. {
  135.     // set up the current date edit field.
  136.     SetDlgItemText( hDlg, IDE_DATEENT, 
  137.                     Current.DateCreated.AsString().c_str() );
  138.  
  139.     // set up the date due edit field.
  140.     SetDlgItemText( hDlg, IDE_DATEDUE, 
  141.                     Current.DateDue.AsString().c_str() );
  142.  
  143.     // set up the text edit field
  144.     SetDlgItemText( hDlg, IDE_TEXT, Current.Text.c_str() );
  145.  
  146.     // set up the correct radio button
  147.     Button = IDE_HIGH + 1 - Current.Priority;
  148.     CheckRadioButton( hDlg, IDE_LOW, IDE_HIGH, Button );
  149. }
  150.  
  151. //---------------------------------------------------------------------
  152. //
  153. //  void EditBox::CheckButton( HWND hDlg, WPARAM wParam );
  154. //
  155. //  called when the user selects one of the radio buttons.
  156. //
  157. //---------------------------------------------------------------------
  158.  
  159. void EditBox::CheckButton( HWND hDlg, WPARAM wParam )
  160. {
  161.     Button = wParam;
  162.     CheckRadioButton( hDlg, IDE_LOW, IDE_HIGH, Button );
  163. }
  164.  
  165. //---------------------------------------------------------------------
  166. //
  167. //  void EditBox::OkCmd( HWND hDlg );
  168. //
  169. //  called when the user selects the OK button.  Copies data from the
  170. //  dialog into the Todo entry and terminates the dialog.
  171. //
  172. //---------------------------------------------------------------------
  173.  
  174. void EditBox::OkCmd( HWND hDlg )
  175. {
  176.     char temp[100 ];
  177.  
  178.     //  copy date created from dialog.
  179.     GetDlgItemText( hDlg, IDE_DATEENT, temp, sizeof( temp ) );
  180.     {
  181.  
  182.     istrstream date( temp, sizeof( temp ) );
  183.     date >> Current.DateCreated;
  184.     }
  185.  
  186.     //  copy date due from dialog.
  187.     GetDlgItemText( hDlg, IDE_DATEDUE, temp, sizeof( temp ) );
  188.     {
  189.     istrstream date( temp, sizeof( temp ) );
  190.     date >> Current.DateDue;
  191.     }
  192.  
  193.     //  copy text from dialog
  194.     GetDlgItemText( hDlg, IDE_TEXT, temp, sizeof(temp) );
  195.     Current.Text = temp;
  196.  
  197.     //  copy priority from dialog.
  198.     Current.Priority = IDE_HIGH + 1 - Button;
  199.  
  200.     //  mark this entry as modified.
  201.     Current.Dirty = TRUE;
  202.  
  203.     EndDialog( hDlg, TRUE );
  204. }
  205.  
  206. //---------------------------------------------------------------------
  207. //
  208. //  void EditBox::CancelCmd( HWND hDlg );
  209. //
  210. //  called when the user selects the Cancel button.  Terminates the
  211. //  dialog without changing any fields in the entry.
  212. //
  213. //---------------------------------------------------------------------
  214.  
  215. void EditBox::CancelCmd( HWND hDlg )
  216. {
  217.     Result = 1;
  218.     EndDialog( hDlg, TRUE );
  219. }
  220.  
  221. //---------------------------------------------------------------------
  222. //
  223. //  BOOL EditBox::Dispatch( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam );
  224. //
  225. //  dispatches commands.
  226. //
  227. //---------------------------------------------------------------------
  228.  
  229. BOOL EditBox::Dispatch( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
  230. {
  231.     switch( msg )
  232.         {
  233.         case WM_INITDIALOG:
  234.  
  235.             InitDlg( hDlg );
  236.             return TRUE;
  237.  
  238.         case WM_COMMAND:
  239.  
  240.             switch( GET_WM_COMMAND_ID(wParam, lParam) )
  241.                 {
  242.                 case IDE_LOW:
  243.                 case IDE_MEDIUM:
  244.                 case IDE_HIGH:
  245.  
  246.                     CheckButton( hDlg, GET_WM_COMMAND_ID(wParam, lParam) );
  247.                     return TRUE;
  248.  
  249.                 case IDOK:
  250.  
  251.                     OkCmd( hDlg );
  252.                     return TRUE;
  253.  
  254.                 case IDCANCEL:
  255.  
  256.                     CancelCmd( hDlg );
  257.                     return TRUE;
  258.                 }
  259.         }
  260.  
  261.     return ModalDialog::Dispatch( hDlg, msg, wParam, lParam );
  262. }
  263.